package com.lost.octopus.es.helper.entity.query.aggregation;

import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.PipelineAggregationBuilder;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

/**
 * 聚合条件构建器
 * @author zhangbh
 * @date 2022/10/11 0011 11:07
 */
@Data
public class EsAggregations {

    /**
     * 自定义聚合条件
     */
    private List<AggregationBuilder> aggregations;

    /**
     * 自定义聚合条件
     */
    private List<PipelineAggregationBuilder> pipelineAggregations;

    public EsAggregations addAggregation(AggregationBuilder aggregation) {
        if (aggregations == null) {
            aggregations = new ArrayList<>();
        }
        aggregations.add(aggregation);
        return this;
    }

    public EsAggregations addAggregation(PipelineAggregationBuilder pipelineAggregation) {
        if (pipelineAggregations == null) {
            pipelineAggregations = new ArrayList<>();
        }
        pipelineAggregations.add(pipelineAggregation);
        return this;
    }
}
